package prison.pages;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shwread.android.qysw.activity.MainActivity;
import com.shwread.android.qysw10000000.R;
import com.shwread.android.ui.customview.GridViewCustom;
import com.shwread.android.ui.page.AbstractUIPage;
import com.tgx.tina.android.ipc.framework.IUIPage;

import base.tina.core.task.infc.ITaskResult;
import cn.bingoogolapple.bgabanner.BGABanner;
import logic.constants.DefaultConsts;
import prison.adapter.InServiceAdapter;

/**
 * 监狱app--家属端-----所内服务页面
 */
public class InServicePage
        extends
        AbstractUIPage<MainActivity> implements BGABanner.Adapter<ImageView, Integer>
        , BGABanner.Delegate<ImageView, Integer>{
    private static InServicePage instance;

    public static InServicePage getInstance(MainActivity t) {
        if (null == instance) {
            instance = new InServicePage(t);
        }
        return instance;
    }

    public InServicePage(MainActivity t) {
        super(t);
    }

    private TextView tvTitle;
    private ImageView ivPersion;
    private GridViewCustom gridView;
    private BGABanner banner;

    private InServiceAdapter adapter;

    private Integer[] ids = {R.drawable.in_service_icon1,R.drawable.in_service_icon2,R.drawable.in_service_icon3,
            R.drawable.in_service_icon4,R.drawable.in_service_icon5,R.drawable.in_service_icon6,
            R.drawable.in_service_icon7,R.drawable.in_service_icon8,R.drawable.in_service_icon9};
    private String[] names = {"顾送物品","会见约见","汇款办理","会见日期","交通指引","保释假释","我的预约","商品代购","文字留言"};

    @Override
    public <E extends Activity> View createView(E arg0, int arg1) {
        if (null != curMyView) return curMyView;
        curMyView = bActivity.getLayoutInflater().inflate(R.layout.in_service_page, null);
        initData();
        initView();
        return curMyView;
    }

    void initData() {
    }

    void initView() {
        tvTitle = (TextView) curMyView.findViewById(R.id.common_header_name);
        tvTitle.setText(R.string.main_tab_str1);
        ivPersion = (ImageView) curMyView.findViewById(R.id.common_header_persion);
        ivPersion.setVisibility(View.VISIBLE);
        ivPersion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bActivity.goPersonalActivity();
            }
        });

        gridView = (GridViewCustom) curMyView.findViewById(R.id.gridView);
        banner = (BGABanner) curMyView.findViewById(R.id.banner);

        adapter = new InServiceAdapter(bActivity,names,ids);
        gridView.setAdapter(adapter);
        banner.setAdapter(this);
        banner.setData(R.drawable.in_service_banner);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            }
        });
    }

    @Override
    public int enter(IUIPage<?> arg0) {
        return 0;
    }

    @Override
    public int leave(IUIPage<?> arg0) {
        return 0;
    }

    @Override
    public void notifyView(int arg0, Bundle arg1) {
        switch (arg0) {
            case DefaultConsts.UPDATEUI_SPLASH_DELAY_MILLIS:
                break;
        }

    }

    @Override
    public void setStatus(int arg0) {

    }

    @Override
    public View updateView(int arg0, ITaskResult arg1) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void fillBannerItem(BGABanner banner, ImageView itemView, Integer model, int position) {
        Glide.with(bActivity)
                .load(model)
                .placeholder(R.drawable.bg_big_image)
                .error(R.drawable.bg_big_image)
                .dontAnimate()
                .centerCrop()
                .into(itemView);
    }

    @Override
    public void onBannerItemClick(BGABanner banner, ImageView itemView, Integer model, int position) {

    }
}
